package com.zyit.util;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class MapRowMapper implements RowMapper<Map<String,Object>> {
    @Override
    public Map<String, Object> mapperRow(ResultSet rs) throws SQLException {

        ResultSetMetaData metaData = rs.getMetaData();
        int columnCount = metaData.getColumnCount();
        Map<String,Object> map = new HashMap<>();

        for(int i = 1;i<=columnCount;i++){
            String columnLabel = metaData.getColumnLabel(i);
            map.put(columnLabel,rs.getObject(columnLabel));
        }
        return map;
    }
}